local skel = fk.CreateSkill {
  name = "emo__tiancuan",
}

Fk:loadTranslationTable{
  ["emo__tiancuan"] = "天篡",
  [":emo__tiancuan"] = "当你跳过一个阶段时，你可以令一名其他角色于下回合开始时执行一个相同阶段。",

  ["@emo__tiancuan"] = "天篡",
  ["#emo__tiancuan-choose"] = "天篡：选择一名其他角色，令其下回合开始时执行 %arg",
  [""] = "",
}

skel:addEffect(fk.EventPhaseSkipped, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askToChoosePlayers(player, {
      min_num = 1, max_num = 1, targets = room.alive_players, skill_name = skel.name,
      prompt = "#emo__tiancuan-choose:::"..Util.PhaseStrMapper(data.phase)
    })
    if #tos > 0 then
      event:setCostData(self, {tos = tos} )
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    room:addTableMark(to, "@emo__tiancuan", Util.PhaseStrMapper(data.phase))
  end,
})

skel:addEffect(fk.TurnStart, {
  anim_type = "control",
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    return target == player and player:getMark("@emo__tiancuan") ~= 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local mark = player:getMark("@emo__tiancuan")
    for i = #mark, 1, -1 do
      player:gainAnExtraPhase(Util.PhaseStrMapper(mark[i]), skel.name)
    end
    room:setPlayerMark(player, "@emo__tiancuan", 0)
  end,
})

return skel
